package com.imooc.demo.pingshu;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.seimicrawler.xpath.JXDocument;
import org.seimicrawler.xpath.JXNode;

import java.io.IOException;
import java.util.List;

//@SpringBootApplication
public class ListThread  extends  Thread{

	private final String url;

	public static void log(String log){
		System.out.println("log-> "+log );
	}

	public static final String  host = "https://www.pingshu365.com";


	public ListThread(String spliderUrl){
		this.url = spliderUrl;
	}


	@Override
	public void run() {
		super.run();

		Document doc = null;
		try {
			doc = Jsoup.connect(url)
                    .header("Accept", "*/*")
                    .header("Accept-Encoding", "gzip, deflate")
                    .header("Accept-Language", "zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3")
                    .header("Content-Type", "application/json;charset=UTF-8")
                    .header("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:48.0) Gecko/20100101 Firefox/48.0")
                    .timeout(10000).ignoreContentType(true).get();
		} catch (IOException e) {
			e.printStackTrace();
		}

		JXDocument jxDocument = JXDocument.create(doc);

		List<JXNode> jxNodes = jxDocument.selN("//div[@class='book']/div[@class='pic']/a");


		for (JXNode node :jxNodes) {

			log(node.toString());

			// title
			log(node.sel("//a/@title").get(0).asString());

			//// href
			log(host+ node.sel("//a/@href").get(0).asString());

			//// pic src
			log(host+node.sel("//a/img/@src").get(0).asString());


		}


		List<JXNode> textnodes = jxDocument.selN("//div[@class='book']/div[@class='text']/ul");


		for (JXNode node :textnodes) {
			// 播讲
			log(node.sel("//li[1]/text()").get(0).asString());
			// 作者
			log(node.sel("//li[2]/text()").get(0).asString());
			// 分类
			log(node.sel("//li[3]/text()").get(0).asString());

			// 格式
			log(node.sel("//li[4]/text()").get(0).asString());

			// 音质
			log(node.sel("//li[5]/text()").get(0).asString());

			// 时间
			log(node.sel("//li[6]/text()").get(0).asString());

			// 语言
			log(node.sel("//li[7]/text()").get(0).asString());

			// 状态
			log(node.sel("//li[8]/text()").get(0).asString());

			// 标签
			log(node.sel("//li[9]/a/text()").toString());

			// 简介
			log(node.sel("//li[10]/p/text()").get(0).asString());

			log("---++++----");

		}



	}




}
